/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.creatjobmanage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.creatjobmanage.entity.CreatJobPart;
import com.lczyfz.campusinfo.modules.creatjobmanage.service.CreatJobPartService;

import java.util.List;

/**
 * 园区项目内容和名称Controller
 * @author zms
 * @version 2018-03-26
 */
@Controller
@RequestMapping(value = "${adminPath}/creatjobmanage/creatJobPart")
public class CreatJobPartController extends BaseController {

	@Autowired
	private CreatJobPartService creatJobPartService;


	@ModelAttribute
	public CreatJobPart get(@RequestParam(required=false) String id) {
		CreatJobPart entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = creatJobPartService.get(id);
		}
		if (entity == null){
			entity = new CreatJobPart();
		}
		return entity;
	}
	
	@RequiresPermissions("creatjobmanage:creatJobPart:view")
	@RequestMapping(value = {"list", ""})
	public String list(CreatJobPart creatJobPart, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CreatJobPart> page = creatJobPartService.findPage(new Page<CreatJobPart>(request, response), creatJobPart);
		List<CreatJobPart> creatjobparts = creatJobPartService.findList(creatJobPart);
		model.addAttribute("creatjobparts",creatjobparts);
		model.addAttribute("page", page);
		return "modules/creatjobmanage/creatJobPartList";
	}

	@RequiresPermissions("creatjobmanage:creatJobPart:view")
	@RequestMapping(value = "form")
	public String form(CreatJobPart creatJobPart, Model model) {
		model.addAttribute("creatJobPart", creatJobPart);
		return "modules/creatjobmanage/creatJobPartForm";
	}

	@RequiresPermissions("creatjobmanage:creatJobPart:edit")
	@RequestMapping(value = "save")
	public String save(CreatJobPart creatJobPart, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, creatJobPart)){
			return form(creatJobPart, model);
		}
		creatJobPartService.save(creatJobPart);
		addMessage(redirectAttributes, "保存园区项目内容和名称成功");
		return "redirect:"+Global.getAdminPath()+"/creatjobmanage/creatJobPart/?repage";
	}
	
	@RequiresPermissions("creatjobmanage:creatJobPart:edit")
	@RequestMapping(value = "delete")
	public String delete(CreatJobPart creatJobPart, RedirectAttributes redirectAttributes) {
		creatJobPartService.delete(creatJobPart);
		addMessage(redirectAttributes, "删除园区项目内容和名称成功");
		return "redirect:"+Global.getAdminPath()+"/creatjobmanage/creatJobPart/?repage";
	}

}